package com.shuker.design.abstarct.factory;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * @author ：Shuker
 * @date ：Created in 2022/1/11 17:15
 * @description：JDK代理
 * @version: 1.0
 */
public class JDKProxy {

    public static <T> T getProxy(Class<T> interfaceClass,ICacheAdapter iCacheAdapter) throws Exception{
        InvocationHandler handler = new JDKInvocationHandler(iCacheAdapter);
        ClassLoader classLoader= Thread.currentThread().getContextClassLoader();
        Class<?>[] classes = interfaceClass.getInterfaces();
        return (T) Proxy.newProxyInstance(classLoader,new Class[]{classes[0]},handler);
    }
}
